import { Injectable } from '@nestjs/common';
//const nodermailer = require('nodemailer');
import {createTransport} from 'nodemailer';

@Injectable()
export class EmailService {
  transpoter = createTransport({
    //host:'smtp.qq.com',//邮箱服务的主机，如smtp.qq.com
    //port:'',//对应的端口号
    service:'qq',
    //开启安全连接
    secure:true,
    //secureConnection:false,
    //用户信息
    auth:{
      user:'1741750591@qq.com',
      pass:'bronzvjahfvvfbdj'
    }
  });

  sendTo(from,to,subject,text){
    //设置收件人信息
    let mailOptions={
      from:from,//谁发的
      to:to,//发给谁
      subject:subject,//主题是什么
      text:text,//文本内容
      html:'',//html模板

      //附件信息
      attachments:[
        {
          filename:'',
          path:'',
        }
      ]
    };

    this.transpoter.sendMail(mailOptions,(error,info)=>{
      if(error){
        console.log(error)
        return;
      }
      console.log(`Message: ${info.messageId}`);
      console.log(`sent: ${info.response}`);
    });
  }

}
